import hyRequest from "../..";
import { getCurrentToken } from "../login";
const token = getCurrentToken();

/**
 * @获取列表
 * @param query
 * @returns
 */
export const getProgrammeList = (query: {
  pageNum: number;
  pageSize: number;
}) => {
  return hyRequest.get({
    url: "/programme/list",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    params: query,
  });
};
/**
 * @修改方案
 * @param body
 * @returns
 */
export const modifyProgrammeInfo = (body: {
  content?: string | null;
  createBy?: string | null;
  examinationIds: number[];
  id: number | null;
  illnessId?: number;
  programmeExaminationList?: any[];
  programmeExaminations?: {
    createBy: string;
    createTime: string;
    examinationId: number;
    id: number;
    programmeId: number;
    remark: null;
    updateBy: string;
    updateTime: string;
  }[];
  programmeTasks?: {
    createBy: string;
    createTime: string;
    taskId: number;
    id: number;
    programmeId: number;
    remark: null;
    updateBy: string;
    updateTime: string;
  }[];
  taskIds: number[];
  title?: string | null;
  updateBy?: string;
  updateTime?: string;
}) => {
  return hyRequest.put({
    url: "/programme",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    data: body,
  });
};

/**
 * @通过用户id获取方案
 * @param id
 * @returns
 */
export function getProgrammeDetailById(userId: number) {
  return hyRequest.get({
    url: `/programme/getProgrammeByUserId/${userId}`,
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });
}
/**
 * @新增
 * @param body
 * @returns
 */
export function addProgrammeInfo(body: {
  content: string | null;
  createBy: null;
  creatTime: null;
  examinationIds: number[];
  id: null;
  illnessId: number;
  programmeExaminationList: any[];
  taskIds: number[];
  title: string | null;
  updateBy: null;
  updateTime: null;
}) {
  return hyRequest.post({
    url: "/programme",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    data: body,
  });
}

/**
 * @通过方案id获取已选任务id和已选检查id
 * @param programmeId
 * @returns
 */
export function getSelectedTasksAndExaminationIdsByProgrammeId(
  programmeId: number
) {
  return hyRequest.get({
    url: `/programme/getSelectedTasksAndExaminationIdsByProgrammeId/${programmeId}`,
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });
}

/**
 * @通过id获取方案详细信息
 * @param id
 * @returns
 */
export function getProgrammeByProgrammeId(id: number) {
  return hyRequest.get({
    url: `/programme/${id}`,
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });
}

/**
 * @批量删除
 * @param ids
 * @returns
 */
export function deleteProgrammeById(ids: string[]) {
  const idsStr = ids.join(",");
  return hyRequest.delete({
    url: `/programme/${idsStr}`,
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });
}

/**
 * @导出方案列表
 */

export function exportProgramme(query: { pageSize: number; pageNum: number }) {
  return hyRequest.post({
    url: "/programme/export",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    params: query,
    responseType: "blob",
  });
}
